import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  ManyToMany,
  JoinTable,
} from "typeorm";
import { Posts } from "./Posts";

@Entity("tags")
export class Tags {
  @PrimaryGeneratedColumn({
    type: "int",
    name: "id",
    comment: "主键id",
  })
  id: number;

  @Column({
    type: "varchar",
    name: "name",
    nullable: false,
    unique: true,
    comment: "tag名称",
  })
  name: string;

  // 多对多关系，需要使用中间表进行关联
  @ManyToMany((type) => Posts, (post) => post.tags)
  @JoinTable({ name: "tags_posts" }) // 手动指定中间表名字
  posts: Posts[];
}
